﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.Xml.Linq;
//--for CrystalReports's ReportDocument.
//using CrystalDecisions.CrystalReports.Engine; 

public partial class Pages_manufacturing_statement : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {



        string stServerName = "UIU-CSELAPTOP";
        string stDatabaseName = "DB2011";
        string stUserID = "sa";
        string stPassword = "1234";



        ////--Initializing CrystalReport
        //ReportDocument myReportDocument;
        //myReportDocument = new ReportDocument();
        //myReportDocument.Load(Server.MapPath("manufacturing_account.rpt"));
        ////myReportDocument.SetDataSource(ds);
        ////--Binding report with CrystalReportViewer
        //CrystalReportViewer1.ReportSource = myReportDocument;
        //CrystalReportViewer1.DataBind();

        
        
        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = stServerName;
        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = stDatabaseName;
        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = stUserID;
        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = stPassword;
        
     }




    protected void Button1_Click(object sender, EventArgs e)
    {
        decimal month = Convert.ToDateTime(TextBoxDate.Text.ToString()).Month;
        decimal year = Convert.ToDateTime(TextBoxDate.Text.ToString()).Year;

        ////--Sql string
        //String strCmd = "";
        //strCmd += "Select EmployeeID, LastName, FirstName, Title, BirthDate, ";
        //strCmd += "Address, City, Region, PostalCode, Country, HomePhone ";
        //strCmd += "From Employees ";
        ////--Opening Sql Connection
        //string strConn = ConfigurationManager.AppSettings["connectionstring"];
        //SqlConnection sqlConn = new SqlConnection(strConn);
        //DataSet ds = new DataSet();
        //SqlDataAdapter da = new SqlDataAdapter(strCmd, sqlConn);
        ////--this statement is very important, here the table name should 
        ////--match with the XML Schema table name 
        //da.Fill(ds, "Employees");
        ////--Closing Sql Connection
        //sqlConn.Close();
        ////--(Optional) I have used it to disable the properties
        //CrystalReportViewer1.DisplayGroupTree = false;
        //CrystalReportViewer1.HasCrystalLogo = false;
        ////--Initializing CrystalReport
        //ReportDocument myReportDocument;
        //myReportDocument = new ReportDocument();
        //myReportDocument.Load(Server.MapPath("Employees.rpt"));
        //myReportDocument.SetDataSource(ds);
        ////--Binding report with CrystalReportViewer
        //CrystalReportViewer1.ReportSource = myReportDocument;
        //CrystalReportViewer1.DataBind();




        //ReportDocument rd;
        string stServerName = "UIU-CSELAPTOP";
        string stDatabaseName = "DB2011";
        string stUserID = "sa";
        string stPassword = "1234";


        ////DataSet ds = new DataSet();
        ////ds.ReadXml(Server.MapPath("App_Data/XMLFile.xml"));

        //OracleAccess oa = new OracleAccess(Session["loginID"].ToString(), Session["pwd"].ToString(), Session["database"].ToString());
        //DataSet bidData = oa.GetBidTemplate(Convert.ToInt32(BidId));
        //bidData.Tables[0].TableName = "DTPrint";


        //ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
        //crConnectionInfo.ServerName = "BRAVEALI-PC"; 
        //crConnectionInfo.DatabaseName = "SCM_TEST"; 
        //crConnectionInfo.UserID = "sa"; 
        //crConnectionInfo.Password = "myDB Password"; 
        //ReportDocument report = new ReportDocument(); 
        //report.Load(@"D:\Project's\SCM Reports\Total_Sales_Comparision.rpt"); 
        //report.SetParameterValue("@invcm_date_from", Convert.ToDateTime(TextBox4.Text)); 
        //report.SetParameterValue("@invcm_date_to", Convert.ToDateTime(TextBox5.Text)); 
        //CrystalReportViewer1.ReportSource = report; //CrystalReportViewer1.RefreshReport(); 



        //string con = @"Provider=SQLSql;Data Source=CSE-PC\SQLEXPRESS;User ID=sa;Initial Catalog=DB2011;Password=1234";

        //StringBuilder sv = new StringBuilder(con);

        //SqlConnection _oleConn = new SqlConnection();
        //_oleConn.ConnectionString = sv.ToString();
        //string cmd1 = "select * from type";

        //SqlCommand comm = new SqlCommand(cmd1, _oleConn);

        //SqlDataAdapter da = new SqlDataAdapter();
        //DataSet ds = new DataSet();

        //da.SelectCommand = comm;
        //da.Fill(ds, "DTEmployees");


        ////ds.Tables[0].TableName = "DTEmployees";
        //rd = new ReportDocument();
        //rd.Load(Server.MapPath("myreport.rpt"));
        //rd.SetDataSource(ds);
        //CrystalReportViewer1.conn
        //CrystalReportViewer1.ReportSource = rd;
        //CrystalReportViewer1.DataBind();

        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = stServerName;
        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = stDatabaseName;
        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = stUserID;
        //CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = stPassword;
        
        
     //   string strquery1 = "select m.itype, m.icode, n.descript,o.iname, m.cumamount, m.cumton" +
     //                       " from manufac2 as m" +
     //                       " inner join type as n on m.itype=n.code" +
     //                       " inner join stock as o on m.itype=o.itype and m.icode=o.icode" +
     //                       " where m.month='" + month.ToString() + "' and m.year='" + year.ToString() + "' and n.varfield='ITYPE'" +
     //                       " order by o.iname";
     //   string strQuery2 = "select * from memo" +
     //                       " where month(date)='" + month.ToString() + "' and year(date)='" + year.ToString() + "' and w_ton < 0 and (itype=17 or itype=18)";
     //   DataSet ds = new DataSet();
     //   Common.Getdata(ds, strquery1, "t1");
     //   Common.Getdata(ds, strQuery2, "t2");
     //   GridView1.DataSource = ds.Tables["t1"];
     //   GridView1.DataBind();

     //   ds.Tables["t1"].Columns.Add("amount", typeof(decimal));
     //   ds.Tables["t1"].Columns.Add("ton", typeof(decimal));
     //   foreach (DataRow t1row in ds.Tables["t1"].Rows)
     //   {
     //       t1row["ton"] = 0;
     //       t1row["amount"] = 0;
     //   }
     //   foreach (DataRow t2row in ds.Tables["t2"].Rows)
     //   {
     //       if (string.IsNullOrEmpty(t2row["cost"].ToString()))
     //                  t2row["cost"] = 0;
     //   }
     //   foreach (DataRow t1row in ds.Tables["t1"].Rows)
     //       foreach (DataRow t2row in ds.Tables["t2"].Rows)
     //          if ((Convert.ToDecimal(t1row["itype"]) == Convert.ToDecimal(t2row["itype"])) && (Convert.ToDecimal(t1row["icode"]) == Convert.ToDecimal(t2row["icode"])))
     //           {
     //                   t1row["ton"] = Convert.ToDecimal(t1row["ton"]) + Convert.ToDecimal(t2row["w_ton"]);
     //                   t1row["amount"] = Convert.ToDecimal(t1row["amount"]) + Convert.ToDecimal(t2row["w_ton"])*(-1) * Convert.ToDecimal(t2row["cost"]);
     //           }

     //   GridView1.DataSource = ds.Tables["t1"];
     //   GridView1.DataBind();

     ////   #region connect to database and save 

     //   string conString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
     //   SqlCommand myCommInsert = new SqlCommand();
     //   myCommInsert.Connection = new SqlConnection(conString);
     //   myCommInsert.Connection.Open();

     //   string strQuery0 = "delete from dbo.Report_manufacturing";
     //   myCommInsert.CommandText = strQuery0;
     //   myCommInsert.ExecuteNonQuery();
        

     //   foreach (DataRow t1row in ds.Tables["t1"].Rows)
     //   {
     //       string strQuery = "INSERT INTO [DB2011].[dbo].[Report_manufacturing] (" +
     //      "[itype]" +
     //      ",[icode]" +
     //      ",[descript]"+
     //      ",[iname]" +
     //      ",[cumamount]" +
     //      ",[cumton]" +
     //      ",[amount]" +
     //      ",[ton])" +
     //"VALUES " +
     //      "('" + t1row["itype"] + "'," +
     //       "'" + t1row["icode"] + "'," +
     //       "'" + t1row["descript"] + "'," +
     //       "'" + t1row["iname"] + "'," +
     //       "'" + t1row["cumamount"] + "'," +
     //       "'" + t1row["cumton"] + "'," +
     //       "'" + t1row["amount"] + "'," +
     //      "'" + t1row["ton"] + "')";


     //       myCommInsert.CommandText = strQuery;
     //       myCommInsert.ExecuteNonQuery();
     //   }



     //   myCommInsert.Connection.Close();





    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
